









<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>JUnice - JUnice core - The JUniceRunner</title>
    <link rel="stylesheet" href="./css/maven-theme.css" type="text/css" />
    <link rel="stylesheet" href="./css/maven-base.css" type="text/css"/>
    <link rel="stylesheet" href="./css/prettify.css" type="text/css"/>
    <link rel="stylesheet" href="./css/print.css" type="text/css" media="print" />
    <script type="text/javascript" src="./js/prettify.js"></script>
    <script type="text/javascript" src="./js/niftycube.js"></script>
    <script type="text/javascript">
        window.onload=function() {
            Nifty("div\#wrapper", "big");
            Nifty("div#breadcrumbs", "small");
            Nifty("div\#navcolumn", "small");
            Nifty("div.source", "medium");
            prettyPrint();
        }
    </script>
          <meta name="author" content="Marco Speranza and Simone Tripodi" />
          </head>
  <body>
    <div id="wrapper">
        <div id="banner">
                        <div id="bannerLeft">
    
            JUnice
    
            </div>
                            <div class="clear">
            <hr/>
          </div>
        </div>
        <div id="breadcrumbs">
              
  

  
    
            
  
    
            <div class="xleft">
        <span id="publishDate">Last Published: 2010-03-24</span>
                  &nbsp;| <span id="projectVersion">Version: 1.1</span>
                      </div>
                <div class="xright">      
  

  
    
            
  
    
  </div>
          <div class="clear">
            <hr/>
          </div>
        </div>
        <div id="leftColumn">
          <div id="navcolumn">
               
  

  
    
            
  
    
                       <h5>JUnice</h5>
            <ul>
              
    <li class="none">
                    <a href="index.html">Home</a>
          </li>
              
    <li class="none">
              <strong>The core - JUniceRunner</strong>
        </li>
              
    <li class="none">
                    <a href="guice.html">Guice integration</a>
          </li>
              
    <li class="none">
                    <a href="mock.html">Mock Framework integration</a>
          </li>
              
    <li class="none">
                    <a href="JUnice-1.1.pdf">PDF User Manual</a>
          </li>
          </ul>
              <h5>Project Documentation</h5>
            <ul>
              
                
                    
                  
                  
                  
                  
                  
                  
                  
                  
                  
              
        <li class="collapsed">
                    <a href="project-info.html">Project Information</a>
                </li>
              
                
                    
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
              
        <li class="collapsed">
                    <a href="project-reports.html">Project Reports</a>
                </li>
          </ul>
              <h5>External Links</h5>
            <ul>
              
    <li class="none">
                    <a href="">Project Page</a>
          </li>
              
    <li class="none">
                    <a href="../google-guice/">Google Guice</a>
          </li>
              
    <li class="none">
                    <a href="http://www.junit.org" class="externalLink">JUnit</a>
          </li>
              
    <li class="none">
                    <a href="http://easymock.org/" class="externalLink">Easy-Mock</a>
          </li>
              
    <li class="none">
                    <a href="http://mockito.org/" class="externalLink">Mockito</a>
          </li>
          </ul>
                                               <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
            <img class="poweredBy"
                 alt="Built by Maven"
                 src="./images/logos/maven-feather.png"
                 width="90"
                 height="30"
                 border="1" />
          </a>
                           
  

  
    
            
  
    
            </div>
        </div>
        <div id="bodyColumn">
          <div id="contentBox">
            <div class="section"><h2>JUnice core - The JUniceRunner</h2>
<p>The core of <i>JUnice</i> is the <tt>com.junice.JUniceRunner</tt> class, that's a <i>JUnit Runner</i> and extends <i>org.junit.internal.runners.BlockJUnit4ClassRunner</i> For each test case the <i>JUniceRunner</i> initializes a google-guice <i>injector</i> before that your test case class is instantiated.</p>
<p>So you have an injector ready to use already into any method <b>@BeforeClass</b>.</p>
</div>
<div class="section"><h2>Getting Started</h2>
<p>To use <i>JUnice</i> users have to annotate the <i>junit</i> test class in the following way:</p>
<div class="source"><pre>@RunWith(JUniceRunner.class)
public class SimpleTest {

   @com.google.inject.Inject
   private com.google.inject.Injector injector;

   @org.junit.BeforeClass
   public static void setUpYourClass(){
        // use injector.
        injector.getInstance(AcmeService.class);  
   }

}</pre>
</div>
<p>The <i>JUnice</i> runner can be used also in a super class:</p>
<div class="source"><pre>@com.google.inject.ImplementedBy(AcmeDatabasePoolImpl.class)
public interface AcmeDatabasePool {

    void open();

    void close();
}</pre>
</div>
<div class="source"><pre>@RunWith(JUniceRunner.class)
abstract public class DatabasePoolInitTest {

   @com.google.inject.Inject
   private static AcmeDatabasePool pool;

   @org.junit.BeforeClass
   public static void setUpYourClass(){
        pool = injector.getInstance(AcmeDatabasePool.class);
        pool.open();
        ...  
   }

   @org.junit.AfterClass
   public static void setUpYourClass(){
        ...
        pool.close();
        ...
   }

}</pre>
</div>
<div class="source"><pre>public class DatabaseClassTest  extends DatabasePoolInitTest{

   @org.junit.Test
   public  void test(){
        ...   
   }

}</pre>
</div>
</div>

          </div>
        </div>
        <div class="clear">
          <hr/>
        </div>
        <div id="footer">
          <div class="xright">Copyright &#169;         
   
          2010.
    
      All Rights Reserved.    
  

  
    
            
  
    
  </div>
          <div class="clear">
            <hr/>
          </div>
        </div>
    </div>
  </body>
</html>
